package com.ljkj.zjf.common;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;

import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;


public class CacheManager {

	private static LoadingCache<String, String> session = CacheBuilder.newBuilder().expireAfterAccess(7, TimeUnit.DAYS).build(new CacheLoader<String, String>() {
		@Override
		public String load(String key) throws Exception {
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			String date = sdf.format(new Date());
			System.out.println("登录成功,存储token为[" + key + "]的会话,值为" + date);
			return date;
		}
	});

	public static LoadingCache<String, String> getSession() {
		return session;
	}

	public static void main(String[] args) throws ExecutionException {
		 String uuid = RandomCode.makeCode();
         CacheManager.getSession().get(uuid);
         System.out.println(uuid);
	}

}
